/*获取验证码*/
var isPhone = 1;
function getCode(e,ent){
	//checkPhone(); //验证手机号码
	if(isPhone){
		
       //hjl start 
		var mobile = $('#tel').val() || $('#mobile').val();

      console.log(mobile);
        var event = ent;

        url = '/api/sms/send';

        $.ajax({
            	url:url,
            	type:'post',
            	data:{mobile:mobile,event:event},
            	success:function(res){

                console.log(res);

            		if(res.code==1){
            			resetCode(); //倒计时
                   alert('发送成功');
            		}else{
                   alert(res.msg);
            		}
                   
            	},
            	dataType:'json'

            });

        //hjl end

	}else{
		$('#tel').focus();
	}	
}
//验证手机号码
function checkPhone(){
	var tel = $('#tel').val();
	var pattern = /^1[0-9]{10}$/;
	isPhone = 1;
	if(tel == '') {
		alert('请输入手机号码');
		isPhone = 0;
		return;
	}
	if(!pattern.test(tel)){
		alert('请输入正确的手机号码');
		isPhone = 0;
		return;
	}
}
//倒计时
function resetCode(){
	$('#getcode').hide();
	$('#second').html('60');
	$('#regetcode').show();
	var second = 60;
	var timer = null;
	timer = setInterval(function(){
		second -= 1;
		if(second >0 ){
			$('#second').html(second);
		}else{
			clearInterval(timer);
			$('#getcode').show();
			$('#regetcode').hide();
		}
	},1000);
}


function new_getCode(e){
  //checkPhone(); //验证手机号码
  if(isPhone){
    resetCode2(); //倒计时
  }else{
    $('#tel').focus();
  }  
}

function resetCode2(){
  $('#getcode2').hide();
  $('#second2').html('60');
  $('#regetcode2').show();
  var second = 60;
  var timer = null;
  timer = setInterval(function(){
    second -= 1;
    if(second >0 ){
      $('#second2').html(second);
    }else{
      clearInterval(timer);
      $('#getcode2').show();
      $('#regetcode2').hide();
    }
  },1000);
}
